<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"> </script>
</head>
<body>
  <!-- 
    watch 数据是新的的dom还是修改之前的
  -->
  <div id="app">
    <son ref="son" ></son>
    <button @click="destroy">destroy</button>
  </div>
  
<template id="son">
  <div>
    <p ref="p" id="p">销毁组件{{age}}</p>
  </div>
</template>
  <script>
    /*
    在组件的销毁之前看一下有咩有遗憾 有 解决遗憾
    全局监听 全局计时器
    
    */ 
    Vue.component("son",{
      data() {
        return {
          age: 16
        }
      },
      template: "#son",
      beforeDestroy() {
        console.log('销毁前')
        console.log(this)
        console.log(this.age)
        console.log(this.$refs.p)
      },
      destroyed() {
        console.log('销毁完成')
        console.log(this)
        console.log(this.age)
        console.log(this.$refs.p)
        console.log(document.getElementById('p'))
      },

    })

    new Vue({
      el: "#app",
      data: {
        show: true 
      },
      methods: {
        destroy() {
          this.$refs.son.$destroy()
        }
      }
    })

  </script>
</body>
</html>